Token Bucket based distributed rate limiting middleware built using Redis atomic operations to prevent API abuse and protect backend services from overload.
This project was developed to protect backend services from excessive traffic and API abuse. The system uses a Token Bucket algorithm backed by Redis atomic operations to enforce rate limits consistently across multiple application instances. The solution sustained 10,000+ requests per second while maintaining sub-50ms validation latency under load.
+----------------------+
| CLIENT |
+----------+-----------+
|
v
+----------------------+
| SPRING BOOT API |
+----------+-----------+
|
v
+----------------------+
| RATE LIMIT FILTER |
+----------+-----------+
|
v
+----------------------+
| REDIS TOKEN BUCKET |
+----------+-----------+
|
Tokens Available?
|
+----+----+
| |
YES NO
| |
v v
Process HTTP 429
Request Too Many Requests
Each client receives a bucket containing a fixed number of tokens. Every incoming request consumes one token. Tokens are replenished periodically at a configured rate. When the bucket becomes empty, additional requests are rejected until tokens become available again. This approach allows controlled bursts while preventing backend overload.
Redis guarantees bucket state consistency during concurrent access.
In-memory operations enable extremely fast request validation.
Multiple application instances may validate requests simultaneously. Redis atomic operations ensure token counts remain consistent under heavy concurrent traffic. This prevents race conditions and ensures accurate rate limit enforcement across distributed deployments.
REQUESTS / SECOND
VALIDATION LATENCY
RATE LIMIT BYPASS
Extensive concurrent load testing was performed to validate the correctness and scalability of the rate limiting mechanism.
Requests Per Second
Bypass Events
Under Sustained Load
Maintaining consistent bucket state across multiple application instances required Redis-backed atomic operations.
Concurrent requests could attempt token consumption simultaneously. Atomic Redis commands ensured consistency.
The solution needed to validate requests with minimal latency while sustaining thousands of requests per second.
This project deepened my understanding of distributed systems, concurrency control, Redis internals and scalable API protection. It also provided hands-on experience with designing low-latency middleware capable of operating under high request volumes.
Explore the Token Bucket implementation, Redis integration and load testing logic.
OPEN_GITHUB